home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-14 | 4.1 KB | 170 lines | [TEXT/MPS ] |
- /*
- File: TempFocus.cpp
-
- Contains: Stack-based utility classes for requesting and releasing foci.
-
- Written by: Troy Gaul
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- */
-
- // -- Compiler/Preprocessor Switches --
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _EXCEPT_
- // Exceptions define several important macros (eg. CHECKENV)
- // which are used in the SOM method dispatch glue. If Except.h
- // is not included early enough, exceptions may not be thrown
- // correctly when returning from a SOM method with the "ev" parameter set.
- #include <Except.h>
- #endif
-
- // -- Utility Includes --
-
- #ifndef _TEMPFOCUS_
- #include "TempFocus.h"
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Foci_defined
- #include <Foci.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _ODDEBUG_
- #include <ODDebug.h>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
-
- #pragma segment TempFocus
-
-
- //=========================================================================
- // Utilities
- //=========================================================================
-
- //-------------------------------------------------------------------------
- // ::GetSessionFromFrame
- //-------------------------------------------------------------------------
- static ODSession*
- GetSessionFromFrame(Environment* ev, ODFrame* frame)
- {
- TempODPart part = frame->AcquirePart(ev);
- return ODGetSession(ev, part);
- }
-
- //=========================================================================
- // TempFocus
- //=========================================================================
-
- //-------------------------------------------------------------------------
- // TempFocus::TempFocus
- //-------------------------------------------------------------------------
-
- TempFocus::TempFocus( Environment* ev,
- ODTypeToken focusType,
- ODFrame* frame )
- {
- fEv = ev;
- fFrameToFocus = frame;
- fAcquired = kODFalse;
- fFocusType = focusType;
- }
-
- //-------------------------------------------------------------------------
- // TempFocus::TempFocus
- //-------------------------------------------------------------------------
-
- TempFocus::TempFocus( Environment* ev,
- ODFrame* frame )
- {
- fEv = ev;
- fFrameToFocus = frame;
- fAcquired = kODFalse;
- fFocusType = kODNullTypeToken;
- }
-
- //-------------------------------------------------------------------------
- // TempFocus::~TempFocus
- //-------------------------------------------------------------------------
-
- TempFocus::~TempFocus()
- {
- if (fAcquired)
- {
- // Relinquish the clipboard focus
- GetSessionFromFrame(fEv, fFrameToFocus)->GetArbitrator(fEv)
- ->RelinquishFocus(fEv, fFocusType, fFrameToFocus);
- }
- }
-
- //-------------------------------------------------------------------------
- // TempFocus::Request
- //-------------------------------------------------------------------------
-
- ODBoolean TempFocus::Request()
- {
- WASSERT(fFocusType != kODNullTypeToken);
-
- ODArbitrator* arbitrator = GetSessionFromFrame(fEv, fFrameToFocus)->GetArbitrator(fEv);
-
- TempODFrame focusedFrame = arbitrator->AcquireFocusOwner(fEv, fFocusType);
-
- fAcquired = ( fAcquired
- || ODObjectsAreEqual(fEv, fFrameToFocus, focusedFrame)
- || arbitrator->RequestFocus(fEv, fFocusType, fFrameToFocus) );
-
- return fAcquired;
- }
-
- //=========================================================================
- // TempClipboardFocus
- //=========================================================================
-
- ODTypeToken sClipboardToken = kODNullTypeToken;
-
- //-------------------------------------------------------------------------
- // TempClipboardFocus::TempClipboardFocus
- //-------------------------------------------------------------------------
-
- TempClipboardFocus::TempClipboardFocus( Environment* ev, ODFrame* frame )
- : TempFocus(ev, frame)
- {
- if ( sClipboardToken == kODNullTypeToken )
- sClipboardToken = GetSessionFromFrame(ev, frame)->Tokenize(ev, kODClipboardFocus);
-
- fFocusType = sClipboardToken;
- }
-
-